FizzBuzz
Alright, let's start with perhaps the most famous technical interview challenge ever.
Legend has it that this challenge was created as a way for employers to see if recent Computer Science graduates were comfortable with programming fundamentals. Evidently, CS programs were teaching students a lot of theory, but not helping them build problem-solving skills.
Here's how the challenge goes:
/* Write a function that takes a number as a parameter.
• If that number is a multiple of 3, it should return "Fizz". • If that number is a multiple of 5, it should return "Buzz". • If that number is a multiple of both 3 AND 5, it should return "FizzBuzz". • Otherwise, it should return `undefined`.*/
fizzbuzz(2); // undefinedfizzbuzz(3); // "Fizz"fizzbuzz(5); // "Buzz"fizzbuzz(15); // "FizzBuzz"fizzbuzz(40); // "Buzz"fizzbuzz(45); // "FizzBuzz"
Difficulty
This is by far the least challenging problem you'll tackle in this section. I wanted to start off with something relatively straightforward.
That said, it also relies on JS problem-solving skills, which isn't something we've tackled directly in the course.
Playground
To tackle this challenge, you'll provide the definition for the fizzbuzz
function below.
You can use the output in the Result pane to see if your solution works or not.
Code Playground